<?php
//error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
require('./roots.php');
require($root_path.'include/inc_environment_global.php');

/**
* CARE2X Integrated Hospital Information System beta 2.0.1 - 2004-07-04
* GNU General Public License
* Copyright 2002,2003,2004,2005,2006 Elpidio Latorilla
* elpidio@care2x.org, 
*
* See the file "copy_notice.txt" for the licence notice
*/

define('LANG_FILE','interconsulta.php');
define('NO_2LEVEL_CHK',1);
require_once($root_path.'include/inc_front_chain_lang.php');

$thisfile=basename(__FILE__);
$breakfile='interconsulta.php';
$action='interconsulta-save.php'.URL_APPEND.'&update='.$update.'&id='.$id;

require_once($root_path.'include/care_api_classes/class_core.php');
$core=new Core;
require_once($root_path.'include/care_api_classes/class_interconsulta.php');

$interconsulta = new Interconsulta;
$especialidades = $interconsulta->loadEspecialidades();

$temp = $interconsulta->getAllInfoObject($id);

$pid = 10000000;
$soap_id = 1;

// echo "<pre>";
// var_dump($temp);
// echo "</pre>";

extract($temp->FetchRow());

$motivoCierre = '<select name="motivo_cierre">';
$motivoCierre .= '<option value="1" ' . (($motivo_cierre == 1)?('selected'):('')) . '>'.$LDSeleccione.'</option>';
$motivoCierre .= '<option value="2" ' . (($motivo_cierre == 2)?('selected'):('')) . '>'.$LDResuelto.'</option>';
$motivoCierre .= '<option value="3" ' . (($motivo_cierre == 3)?('selected'):('')) . '>'.$LDTraslado.'</option>';
$motivoCierre .= '<option value="4" ' . (($motivo_cierre == 4)?('selected'):('')) . '>'$LDNoAdherencia'</option>';
$motivoCierre .= '</select>';

$clasif = '<select name="clasificacion">';
$clasif .= '<option value="0" ' . (($clasificacion == 0)?('selected'):('')) . '>'.$LDSeleccione.'</option>';
$clasif .= '<option value="1" ' . (($clasificacion == 1)?('selected'):('')) . '>'.$LDExcelente.'</option>';
$clasif .= '<option value="2" ' . (($clasificacion == 2)?('selected'):('')) . '>'.$LDBuena.'</option>';
$clasif .= '<option value="3" ' . (($clasificacion == 3)?('selected'):('')) . '>'.$LDRegular.'</option>';
$clasif .= '<option value="4" ' . (($clasificacion == 4)?('selected'):('')) . '>'.$LDMala.'</option>';
$clasif .= '<option value="5" ' . (($clasificacion == 5)?('selected'):('')) . '>'.$LDMuyMala.'</option>';
$clasif .= '</select>';

$prev = '<input name="interconsultas_previas" type="radio" value="S" ' . (($interconsultas_previas == 'S')?('checked'):('')) . '/>'$LDSi;
$prev .= '<input name="interconsultas_previas" type="radio" value="N" ' . (($interconsultas_previas == 'N')?('checked'):('')) . '/>No';
$prev .= '<input name="interconsultas_previas" type="radio" value="I" ' . (($interconsultas_previas == 'I')?('checked'):('')) . '/>'$LDIgnored;


$c=1;
if (count($especialidades)){
foreach ($especialidades as $temp)
    {
	
        $opts .= '<input type="radio" name="id_especialidad" value="' . $temp["id"] . '">' ;	
							
	if ($temp["descripcion"]=='Medicina Interna'){
		$opts.=$LDMedicinaInterna;
	}
	elseif ($temp["descripcion"]=='Pediatria'){
		$opts.=$LDPediatria;
	}
	elseif ($temp["descripcion"]=='Gineco-obstetra'){
		$opts.=$LDGinecoObstetra;
	}
	elseif ($temp["descripcion"]=='Cirugia'){
		$opts.=$LDCirugia;
	}
	elseif ($temp["descripcion"]=='Cardiologia'){
		$opts.=$LDCardiologia;
	}
	elseif ($temp["descripcion"]=='Dermatologia'){
		$opts.=$LDDermatologia;
	}else{
	$opts.=$temp["descripcion"];
	}



        if(!($c % 4)) $opts .='<br>';
        $c++;
    }

        if(!($c % 4)) $opts .='<br>';
        $c++;
}
}

$etnias = $interconsulta->loadEtnias();
$combo = '<select name="etnia"><option value="0">' . $LDSelect . '</option>';
while ($temp=$etnias->FetchRow())
{
        if($etniaValue == $temp["nr"]){
                $combo .= '<option value="'. $temp["nr"] .'" selected>' . $temp["name"] . '</option>';
        }else{
                $combo .= '<option value="'. $temp["nr"] .'">' . $temp["name"] . '</option>';

        }
}
$combo .= '</select>';

$user = $interconsulta->preloadUserInfo($_SESSION['sess_login_userid']);

$files = $interconsulta->seleccionarNombreAdjuntos($id);

$archivos="";

if (count($files))
{
    foreach($files as $file){
            $name = $file['name'];
            $option="menubar=no,width=600,height=6000,resizable=yes,scrollbars=yes";
    
            if (strlen($name))
            {
                    $url="../../modules/interconsulta/include/showImage.php?id=$id&name=$name ";
                    $archivos .= "<a href=\"javascript: window.open('$url','wblabel','$option'); exit;\">$name</a> ";
    
            }
    }
}

if($archivos=='') $archivos=$LDNinguno;
else{
	$archivos=substr_replace($archivos,'',(strlen($archivos))-2);
 }


# Start Smarty templating here
/**
* LOAD Smarty
*/

# Note: it is advisable to load this after the inc_front_chain_lang.php so
# that the smarty script can use the user configured template theme
?>
                <script  language="javascript">
                function forceSave(){
                        document.aufnahmeform.mode.value="forcesave";
                        document.aufnahmeform.submit();
                }

                function showpic(d){
                        if(d.value) document.images.headpic.src=d.value;
                        if(d.value) document.images.headpic.src=d.value;
                }

                function popSearchWin(target,obj_val,obj_name){
                        urlholder="./data_search.php<?php echo URL_REDIRECT_APPEND; ?>&target="+target+"&obj_val="+obj_val+"&obj_name="+obj_name;
                        DSWIN<?php echo $sid ?>=window.open(urlholder,"wblabel<?php echo $sid ?>","menubar=no,width=400,height=550,resizable=yes,scrollbars=yes");
                }

                function popWin(){
                        urlholder="./interconsulta-adjuntar.php<?php echo URL_REDIRECT_APPEND;?>";
                        DSWIN<?php echo $sid ?>=window.open(urlholder,"wblabel<?php echo $sid ?>","menubar=no,width=400,height=150,resizable=yes,scrollbars=yes");
                }

                function chkform(d) {
                        if(d.interconsultante.value==""){//
                                alert("<?php echo $LDPlsEnterIC; ?>");
                                d.apellido_1.focus();
                                return false;
                        }else if(d.establecimiento.value==""){//
                                alert("<?php echo $LDPlsEnterEstablecimiento; ?>");
                                d.establecimiento.focus();
                                return false;
                        }else if(d.id_paciente.value==""){
                                alert("<?php echo $LDPlsEnterIdPaciente; ?>");
                                d.id_paciente.focus();
                                return false;
                        }else if(d.apellido_1.value==""){
                                alert("<?php echo $LDPlsEnterLastName; ?>");
                                d.apellido_1.focus();
                                return false;
                        }else if(d.name_1.value==""){
                                alert("<?php echo $LDPlsEnterFirstName; ?>");
                                d.name_1.focus();
                                return false;
                        }else if(d.sex[0]&&d.sex[1]&&!d.sex[0].checked&&!d.sex[1].checked){
                                alert("<?php echo $LDPlsSelectSex; ?>");
                                return false;
                        }else if(d.motivo.value==""){//
                                alert("<?php echo $LDPlsEnterMotivo; ?>");
                                d.motivo.focus();
                                return false;
                        }else if(d.antecedentes.value==""){//
                                alert("<?php echo $LDPlsEnterAntecedentes; ?>");
                                d.antecedentes.focus();
                                return false;
                        }
                }

        var http_request = false;
        function request_soap() {
            http_request = false;
            if (window.XMLHttpRequest) { // Mozilla, Safari,...
                http_request = new XMLHttpRequest();
                if (http_request.overrideMimeType) {
                    http_request.overrideMimeType('text/html');
                }
            } else if (window.ActiveXObject) { // IE
                try {
                    http_request = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                    try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) {}
                }
            }
            if (!http_request) {
                alert("<?php echo $LDHttpInst; ?>");
                return false;
            }

            http_request.onreadystatechange = display_soap;
            http_request.open('GET', '../historia_clinica/historia_clinica-soap.php?ficha=soap&pid=<?= $pid ?>&id=<?= $soap_id ?>&update=1&minimal=1', true);
            http_request.setRequestHeader("Connection", "close");
	    http_request.send("");
        }

        function display_soap() {
            if (http_request.readyState == 4) {
                if (http_request.status == 200) {
		  document.getElementById('soap_data').innerHTML = http_request.responseText;
                } else {
                    alert("<?php echo $LDHttpReque; ?>");
                }
            }
        }

<?php
                require($root_path.'include/inc_checkdate_lang.php'); 
?>
                </script>
<?php

require_once($root_path.'gui/smarty_template/smarty_care.class.php');
$smarty = new smarty_care('common');

$smarty->assign('breakfile',$breakfile);
$smarty->assign('action',$action);
$smarty->assign('reg',1);
$smarty->assign('currentUser', $_SESSION['sess_login_userid']);

$smarty->assign('sToolbarTitle',$LDInter);

$smarty->assign('title',$LDEditInter);

$smarty->assign('LDInterconsultante',$LDInterconsultante);
$smarty->assign('sInterconsultanteInput','<input name="interconsultante" type="text" size="35" value="'. $user["name"] . '" readonly>');

$smarty->assign('LDEstablecimiento',$LDEstablecimiento);
$smarty->assign('sEstablecimientoInput','<input name="establecimiento" type="text" size="35" value="'.$establecimiento.'">');

$smarty->assign('LDEspecialidad',$LDEspecialidad);
$smarty->assign('sEpecialidadRadio',$opts);

$smarty->assign('LDPersonData',$LDPersonData);

/* campos para la tabla */
include_once('../../include/inc_date_format_functions.php');
require_once ('../../js/jscalendar/calendar.php');
$calendar = new DHTML_Calendar('../../js/jscalendar/', 'es', 'calendar-system', true);
$calendar->load_files();

$smarty->assign('LDPaciente',$LDCaseNr);
$smarty->assign('sPacienteInput','<input name="id_paciente" type="text" size="35" value="'.$id_paciente.'" readonly>');
$smarty->assign('sPacienteMiniCalendar',"<a href=\"javascript:popSearchWin('paciente')\"><img ".createComIcon($root_path,'b-write_addr.gif','0')."></a>");

$smarty->assign('LDApellido',$LDLastName);
$smarty->assign('sApellidoPacienteInput','<input name="apellido_1" type="text" size="35" value="'.$apellido_1.'">');

$smarty->assign('LDApellido2',$LDLastName2);
$smarty->assign('sApellidoPaciente2Input','<input name="apellido_2" type="text" size="35" value="'.$apellido_2.'">');

$smarty->assign('LDNombre',$LDName);
$smarty->assign('sNombrePacienteInput','<input name="name_1" type="text" size="35" value="'.$name_1.'">');

$smarty->assign('LDNombre2',$LDName2);
$smarty->assign('sNombrePaciente2Input','<input name="name_2" type="text" size="35" value="'.$name_2.'">');

$smarty->assign('LDSexo',$LDSex);
$sCSBuffer='<input id="sexo_paciente_f" name="sex" type="radio" ';
$sCSBuffer .= 'value="f" ';

if($sex=="f") $sCSBuffer.='checked';
$smarty->assign('sFemInput',$sCSBuffer.'>');

$sCSBuffer='<input id="sexo_paciente_m" name="sex" type="radio" ';
$sCSBuffer .= 'value="m" ';

if($sex=="m") $sCSBuffer.='checked';
$smarty->assign('sMasInput',$sCSBuffer.'>');

$smarty->assign('LDFem',$LDFemenino);
$smarty->assign('LDMas',$LDMasculino);

$smarty->assign('LDEstado',$LDStatus);
$sCSBuffer='<input name="estado" type="radio" value="1" ';
if($estado==1) $sCSBuffer.='checked';
$sCSBuffer.='>'.$LDConsultando.' &nbsp;<input name="estado" type="radio" value="2" ';
if($estado==2) $sCSBuffer.='checked';
$sCSBuffer.='>'.$LDConCerrada;

$smarty->assign('LDMotivoCierre',$LDMotivo);
$smarty->assign('sMotivoCierreInput',$motivoCierre);

$smarty->assign('LDClasificacion',$LDClasificacion);
$smarty->assign('sClasificacionInput',$clasif);

$smarty->assign('LDPrevias',$LDInterPrevia);
$smarty->assign('sPreviasInput',$prev);

$smarty->assign('sEstadoInput',$sCSBuffer);

$smarty->assign('LDEtnia',$LDEthnicGroup);
$smarty->assign('sEtniaCombo',$combo);

$listarPaciente ="<a href='../../modules/registration_admission/patient_register_show.php?lang=es&pid=".$id_paciente."&edit=1'><b>Mas datos del paciente</b></a>";
$smarty->assign('LDListarPaciente',$listarPaciente);

$smarty->assign('LDInterData', $LDInterData);

$smarty->assign('LDFecha',$LDDate);
$smarty->assign('sFechaInput','<input name="fecha_hora_consulta" type="text" size="35" readonly value="' . date("d/m/Y H:i:s") . '" value="'.$fecha_hora_consulta.'">');

$smarty->assign('LDMotivo',$LDMotive);
$smarty->assign('sMotivoText','<select name="motivo"><option value="Consulta" ' . (($motivo == 'Consulta')?('selected'):('')) . '>Consulta</option><option value="Asignada" ' . (($motivo == 'Asignada')?('selected'):('')) . '>Asignada</option><option value="STV" ' . (($motivo == 'STV')?('selected'):('')) . '>STV</option><option value="Respondida" ' . (($motivo == 'Respondida')?('selected'):('')) . '>Respondida</option><option value="Cerrada" ' . (($motivo == 'Cerrada')?('selected'):('')) . '>Cerrada</option></select>');



$smarty->assign('LDArchivos',$LDArchivoAdjunto);
$smarty->assign('sListaArchtext',$archivos.'<br><input name="listaArchivos" type="text" size="35" readonly>');
$smarty->assign('sFileBrowser',"<a href=\"javascript:popWin()\"><img ".createComIcon($root_path,'b-write_addr.gif','0')."></a>");

$smarty->assign('LDExamenFisico',$LDPhysEx);
$smarty->assign('sExamenFisicoText','<textarea name="examen_fisico" cols="43" rows="5">'.$examen_fisico.'</textarea>');

$smarty->assign('LDTension',$LDTension);
$smarty->assign('sTensionInput','<input name="presion_arterial" type="text" size="12" maxlength="10">');

$smarty->assign('LDPulso',$LDPulso);
$smarty->assign('sPulsoInput','<input name="pulso" type="text" size="12" maxlength="10">');

$smarty->assign('LDFrecuencia',$LDRespiracion);
$smarty->assign('sFrecuenciaInput','<input name="respiratoria" type="text" size="12" maxlength="10">');

$smarty->assign('LDTemp',$LDTemperatura);
$smarty->assign('sTempInput','<input name="temp" type="text" size="12" maxlength="10">');

$smarty->assign('LDSOAP','S.O.A.P');
$smarty->assign('LDOtros',$LDOtros);



$smarty->assign('LDAntecedentes',$LDBckgrd);
$smarty->assign('sAntecedentesText','<textarea name="antecedentes" cols="43" rows="5">'.$antecedentes.'</textarea>');

$smarty->assign('pbSubmit','<input type="image" '.createLDImgSrc($root_path,'savedisc.gif','0').'  alt="'.$LDSaveData.'" align="absmiddle">');
$smarty->assign('pbReset','<a href="javascript:document.regform.reset()"><img '.createLDImgSrc($root_path,'reset.gif','0').' alt="'.$LDResetData.'" align="absmiddle"></a>');

$smarty->assign('sMainBlockIncludeFile','interconsulta/registrar_interconsulta.tpl');

/**
* show Template
*/
$smarty->display('common/mainframe.tpl');
?>
